home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 103 / XENIATGM103.iso / Shareware / GoLive 5.0 / MM9.Cab / F1496_mscommerce.actions5.asp.9B3B646D_CB56_4EAE_BAB7_3E7E8E41A649 < prev    next >
Text File  |  2000-08-17  |  8KB  |  269 lines

  1. <!-- #INCLUDE FILE="../include/utils.runtime5.asp" -->
  2. <!-- #INCLUDE FILE="../include/mscommerce.runtime5.asp" -->
  3. <SCRIPT runat="server" language="JScript">
  4.  
  5. // *****************************************************************************
  6. //
  7. // actions/mscommerce.runtime5.asp
  8. //
  9. // Dynamic Link runtime support for Microsoft Commerce server.
  10. //
  11. // COPYRIGHT (c) 1999-2000 Adobe Systems Incorporated. All rights reserved.
  12. //
  13. // -----------------------------------------------------------------------------
  14.  
  15.  
  16. // *****************************************************************************
  17. // Commom Setup / Redirection
  18. // *****************************************************************************
  19.  
  20. // -----------------------------------------------------------------------------
  21. // SetupMSCommerce
  22. //
  23. // This function adds hidden fields for FinishMSCommerceAction(), below.
  24. // -----------------------------------------------------------------------------
  25.  
  26.  
  27. function SetupMSCommerce( successDest )
  28. {
  29.     var thisURL = Request( "URL" ) + "?" + Request( "QUERY_STRING" );
  30.     Response.Write( "<input type=\"hidden\" name=\"$return\" value=\"" + thisURL + "\">" );
  31.     Response.Write( "<input type=\"hidden\" name=\"$success_dest\" value=\"" + successDest + "\">" );
  32. }
  33.  
  34.  
  35. // -----------------------------------------------------------------------------
  36. // FinishMSCommerceAction
  37. //
  38. // After the action has completed, this function either redirects back to the
  39. // caller or to $success_dest.
  40. // -----------------------------------------------------------------------------
  41.  
  42. function FinishMSCommerceAction()
  43. {
  44.     var dest = Request( "$success_dest" );
  45.     var nextPage = "";
  46.     if(( 0 < dest.Count )&&( 0 < String( dest ).length )){    // to avoid "undefined"
  47.         nextPage = absolutePath( Request( "$return" ), dest );
  48.     }else{
  49.         nextPage = Request( "$return" );
  50.     }
  51.     Response.Redirect( addArgs( nextPage, URLArgs() ));
  52. }
  53.  
  54.  
  55. // *****************************************************************************
  56. // Add To Cart
  57.  
  58. // -----------------------------------------------------------------------------
  59. // SetupAddToCart
  60. // -----------------------------------------------------------------------------
  61.  
  62. function SetupAddToCart( contentSource, allRecords, SKU, successDest )
  63. {
  64.     //    Close parent <input>
  65.     Response.Write(">");
  66.  
  67.     SetupMSCommerce( successDest );
  68.     Response.Write( "<input type=\"hidden\" name=\"SKU\" value=\"" + SKU + "\">" );
  69.  
  70.     //    Protect original close of parent <input>
  71.     Response.Write( "<" );
  72.     Response.Write( "wbr" );
  73. }
  74.  
  75.  
  76. //-----------------------------------------------------------------------------
  77. // AddToCart
  78. //-----------------------------------------------------------------------------
  79.  
  80. function AddToCart()
  81. {
  82.     if( Request( "SKU" ).Count ){
  83.         SKU = Request( "SKU" );
  84.         if( UseFakeCommerce() ){
  85.             for( i = 0; i < fakeOrderForm.items.data.length; i++ ){
  86.                 if( fakeOrderForm.items.data[i].SKU == SKU ){
  87.                     fakeOrderForm.items.data[i].Quantity++;
  88.                     break;
  89.                 }
  90.             }
  91.             if( i == fakeOrderForm.items.data.length ){
  92.                 fakeOrderForm.items.data[i] = new Object();
  93.                 fakeOrderForm.items.data[i].SKU = SKU;
  94.                 fakeOrderForm.items.data[i].Quantity = 1;
  95.             }
  96.             fakeOrderForm.UpdateBatch();
  97.         }else{
  98.             AssertOrderForm();
  99.             var found = false;
  100.             for( var i = 0; i < mscsOrderForm.items.Count; i++ ){
  101.                 if( mscsOrderForm.items( i ).sku == SKU ){
  102.                     mscsOrderForm.items( i ).quantity++;
  103.                     found = true;
  104.                     break;
  105.                 }
  106.             }
  107.             if( !found )    mscsOrderForm.AddItem( SKU, 1, 0 );
  108.             UpdateOrderForm();
  109.         }
  110.     }
  111.     FinishMSCommerceAction();
  112. }
  113.  
  114.  
  115. //*****************************************************************************
  116. // Purchase Now
  117.  
  118. //-----------------------------------------------------------------------------
  119. // SetupPurchaseNow
  120. //-----------------------------------------------------------------------------
  121.  
  122. function SetupPurchaseNow(contentSource, allRecords, successDest)
  123. {
  124.     // Close parent <input>
  125.     Response.Write( ">" );
  126.  
  127.     SetupMSCommerce( successDest );
  128.  
  129.     // Protect original close of parent <input>
  130.     Response.Write( "<" );
  131.     Response.Write( "wbr" );
  132. }
  133.  
  134.  
  135. //-----------------------------------------------------------------------------
  136. // PurchaseNow
  137. //-----------------------------------------------------------------------------
  138.  
  139. function PurchaseNow()
  140. {
  141.     if (UseFakeCommerce()) {
  142.         Session("FakeShoppingBasket") = "";
  143.         fakeOrderForm = null;
  144.     } else {
  145.         AssertOrderForm();
  146.         mscsOrderFormStorage.DeleteData(null, mscsOrderForm);
  147.     }
  148.  
  149.     FinishMSCommerceAction();
  150. }
  151.  
  152.  
  153. // *****************************************************************************
  154. // Update Totals
  155.  
  156. // -----------------------------------------------------------------------------
  157. // SetupUpdateTotals
  158. // -----------------------------------------------------------------------------
  159.  
  160. function SetupUpdateTotals( contentSource, allRecords )
  161. {
  162.     //    Close parent <input>
  163.     Response.Write( ">" );
  164.  
  165.     SetupMSCommerce( "" );
  166.  
  167.     //    Protect original close of parent <input>
  168.     Response.Write( "<" );
  169.     Response.Write( "wbr" );
  170. }
  171.  
  172.  
  173. // -----------------------------------------------------------------------------
  174. // UpdateTotals
  175. // -----------------------------------------------------------------------------
  176.  
  177. function UpdateTotals()
  178. {
  179.     var args = unescape( String( Request.Form )).split( "&" );
  180.     for( var i = 0; i < args.length; i++ ){
  181.         var qtyArray = 0;
  182.         var qty         = 0;
  183.         var equal = args[i].indexOf( "=" );
  184.         if( args[i].indexOf( "Quantity[" ) == 0 ){
  185.             qtyArray = Number( args[i].substr( 9, equal - 10 ));
  186.             qty         = Number( args[i].substr( equal + 1, args[i].length ));
  187.         }else if( args[i].indexOf( "Quantity" ) == 0 ){
  188.             qtyArray = 1;
  189.             qty         = Number( args[i].substr( equal + 1, args[i].length ));
  190.         }else{
  191.             qtyArray = 0;
  192.         }
  193.  
  194.         if( 0 < qtyArray ){
  195.             if( 0 < qty ){
  196.                 if( UseFakeCommerce() ){
  197.                     fakeOrderForm.items.data[qtyArray-1].Quantity = qty;
  198.                 }else{
  199.                     mscsOrderForm.items( qtyArray - 1 ).Quantity = qty;
  200.                 }
  201.             }else{
  202.                 if( UseFakeCommerce() ){
  203.                     fakeOrderForm.items.data[qtyArray-1].deleted = true;
  204.                 }else{
  205.                     mscsOrderForm.items( qtyArray - 1 ).Quantity = 0;
  206.                 }
  207.             }
  208.         }
  209.     }
  210.     if( UseFakeCommerce() ){
  211.         fakeOrderForm.UpdateBatch();
  212.     }else{
  213.         for( var i = mscsOrderForm.items.Count - 1; 0 <= i; i-- ){
  214.             if( mscsOrderForm.items( i ).quantity == 0 ){
  215.                 mscsOrderForm.items.Delete( i );
  216.             }
  217.         }
  218.         UpdateOrderForm();
  219.     }
  220.     FinishMSCommerceAction();
  221. }
  222.  
  223.  
  224. // *****************************************************************************
  225. // Dispatch
  226. //    
  227. //    if( 0 <= String( Request.ServerVariables( "PATH_TRANSLATED" )).indexOf( "mscommerce.actions5.asp" )){
  228. //        var orderForm = GetOrderForm( "Adobe" );
  229. //    
  230. //        if(( 0 < Request( "$AddToCart" ).Count )||( 0 < Request( "$AddToCart.x" ).Count )){
  231. //            AddToCart();
  232. //    
  233. //        }else if(( 0 < Request( "$PurchaseNow" ).Count )||( 0 < Request( "$PurchaseNow.x" ).Count )){
  234. //            PurchaseNow();
  235. //        }else if(( 0 < Request( "$UpdateTotals" ).Count )||( 0 < Request( "$UpdateTotals.x" ).Count )){
  236. //            UpdateTotals();
  237. //        }
  238. //    }
  239. //    
  240.  
  241. </SCRIPT>
  242.  
  243. <SCRIPT runat="server" language="VBScript">
  244.  
  245.  
  246. ' TODO: port to Jscript above.
  247. ' *****************************************************************************
  248. ' Dispatch
  249.  
  250. if InStr(Request.ServerVariables("PATH_TRANSLATED"), "mscommerce.actions5.asp") then
  251.  
  252.     set orderForm = GetOrderForm( "" )
  253.  
  254.     if Request("$AddToCart").Count > 0 or Request("$AddToCart.x").Count > 0 then
  255.         AddToCart
  256.     elseif Request("$PurchaseNow").Count > 0 or Request("$PurchaseNow.x").Count > 0 then
  257.         PurchaseNow
  258.     elseif Request("$UpdateTotals").Count > 0 or Request("$UpdateTotals.x").Count > 0 then
  259.         UpdateTotals
  260.     else    ' default action
  261.         UpdateTotals
  262.     end if
  263.  
  264. end if
  265.  
  266. </SCRIPT>
  267.  
  268.  
  269.